package com.yeswater.multithread.chapter2.test2_1.test9;

import java.util.concurrent.TimeUnit;

/**
 * author : yeswater
 * date : 2023/10/19
 */

public class Main {
    public static void main(String[] args) throws InterruptedException {
        Service service = new Service();

        MyThread a = new MyThread(service);
        a.setName("a");
        a.start();

        TimeUnit.SECONDS.sleep(1);
        MyThread b = new MyThread(service);
        b.setName("b");
        b.start();
    }

    private static class MyThread extends Thread {

        private final Service service;

        public MyThread(Service service) {
            super();
            this.service = service;
        }

        @Override
        public void run() {
            service.testMethod();
        }
    }

}
